home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d21 / dvload.arc / DVLOAD.C next >
Text File  |  1988-07-08  |  4KB  |  179 lines

  1. /* dvload.c
  2.    by Rod Murillo  303-761-0410  murillo@boulder.colorado.edu
  3.    Start a new task in Desqview from the DOS command line.
  4.  
  5.    NOTE:  You must have the C API Library to compile this.  The
  6.    large memory model is recomended.  If you are new to the C library
  7.    drop me a line if you get frustrated trying to compile your first
  8.    program.  I was.
  9.  
  10.    This program was compiled with Turbo C 1.5
  11.  
  12. */
  13.  
  14. #undef DEBUG
  15. #include <stdio.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <io.h>
  19. #include <fcntl.h>
  20. #include <conio.h>
  21. #include <errno.h>
  22. #include <dvapi.h>
  23.  
  24. /* buffers sizes for storing and reading the PIF */
  25.  
  26. #define PIFSIZE  416
  27. #define BUFFSIZE 512
  28.  
  29. /* parameter line flag position and mask in PIF */
  30.  
  31. #define PARAMFLAG 368     /* flag is at offset 368 */
  32. #define PARAMSET 0x40     /* turn this bit on to flag command line presence */
  33.  
  34. /* error codes from startapp */
  35.  
  36. #define NODV     1    /* desqview is not loaded */
  37. #define OPENERR  2    /* error on opening PIF */
  38. #define READERR  3    /* error on reading PIF */
  39. #define STARTERR 4    /* error on starting application */
  40. #define PARAMERR 5    /* error in command line options */
  41.  
  42. #define MAXERR   5
  43.  
  44. /* command line argument paramters */
  45.  
  46. #define COMLINE_START  165    /* PIF buffer position for command lines args */
  47. #define COMLINE_END    228    /* end position for start line */
  48.  
  49. char pifbuff[BUFFSIZE];      /* PIF buffer */
  50.  
  51. main(argc,argv)
  52. int argc;
  53. char *argv[];
  54. {
  55.  
  56.    /* function prototypes */
  57.  
  58.    int startapp(char *,int, char *);   /* handle PIF reading and app start */
  59.    void errmesg(int);              /* print error messages */
  60.  
  61.    /* declarations */
  62.  
  63.    char *pifspec = "c:\\dv\\00-pif.dvp";
  64.    int errcode;
  65.  
  66.    /* begin */
  67.  
  68.    if (argc < 2 || argc > 3) {
  69.       puts("usage: dvl prefix [\"parameters\"]");
  70.       exit(PARAMERR);
  71.    }
  72.  
  73.    /* load the PIF spec code */
  74.    pifspec[6] = argv[1][0];
  75.    pifspec[7] = argv[1][1];
  76.  
  77.    errcode = startapp(pifspec,argc,argv[2]);
  78.  
  79.    if (errcode != 0)
  80.       errmesg(errcode);
  81.    exit(errcode);
  82.  
  83. }     /* end of function main() */
  84.  
  85. /* startapp() */
  86.  
  87. int startapp(app,argc,args)
  88. char app[];
  89. int argc;
  90. char args[];
  91. {
  92.  
  93.    int i, j, inhandle;
  94.    unsigned long int winhan;
  95.  
  96.    if (api_init() == 0)
  97.       return(NODV);
  98.  
  99.    if ((inhandle = open(app, O_RDWR | O_BINARY)) < 0)
  100.       return(OPENERR);
  101.  
  102.    if ((read(inhandle, pifbuff, BUFFSIZE)) != PIFSIZE)
  103.       return(READERR);
  104.  
  105.    close(inhandle);
  106.  
  107.    if (argc == 3) {   /* check for a param string */
  108.  
  109.       /* load the param string into the buffer */
  110.  
  111.       for (i=COMLINE_START; i < COMLINE_END - COMLINE_START + 1; i++)
  112.          pifbuff[i] = ' ';
  113.  
  114.       for (i=COMLINE_START, j=0; j < strlen(args) && j < COMLINE_END - COMLINE_START; i++, j++) {
  115.          pifbuff[i] = args[j];
  116.       }
  117.       pifbuff[i] = '\0';
  118.       pifbuff[PARAMFLAG] = pifbuff[PARAMFLAG] | PARAMSET;  /* flag params on */
  119.  
  120.    }
  121.  
  122.    if (app_start(pifbuff,PIFSIZE) == 0)
  123.       return(STARTERR);
  124.    else
  125.       return(0);
  126. }
  127.  
  128.  
  129. /* errmesg() */
  130.  
  131. void errmesg(code)
  132. int code;
  133. {
  134.    char *errorstring;
  135.    unsigned long int winhan;
  136.  
  137.    switch (code) {
  138.       case NODV:          /* desqview is not running */
  139.          errorstring = "This program must run under DESQview 2.01 or later.";
  140.          break;
  141.       case OPENERR:       /* error on opening PIF */
  142.          errorstring = "Error on opening PIF file.";
  143.          break;
  144.       case READERR:       /* error on reading PIF */
  145.          errorstring = "Error on reading PIF file.";
  146.          break;
  147.       case STARTERR:      /* error on starting application */
  148.          errorstring = "Error in starting application.";
  149.          break;
  150.    }
  151.    if (code != NODV) {
  152.       winhan = win_me();
  153.       win_disperor(winhan,errorstring,strlen(errorstring),2,30,0,0);
  154.    } else
  155.       printf("%s\n",errorstring);
  156.  
  157.    return;
  158. }
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.